/*
 * CS 567 GUI - Semester Project - "DecisionLists"
 * Jason Frank
 * Spring 2011
 *
 * This File:  A Strategy pattern class. Its job is to take a buffered image, resize it, then draw
 *             the resized image to it's panel. Thus client code can use the resultant JPanel to add
 *             to it's layout.
 *
 */

package Decision_Lists;

import com.thebuzzmedia.imgscalr.Scalr;
import java.awt.Dimension;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

/*
 */
public class ImageResizeToPanel extends JPanel  {

  private BufferedImage image;
  int maxSidePixels;

  // Constructor
  public ImageResizeToPanel(BufferedImage image, int maxSidePixels)  {

    this.image = image;
    this.maxSidePixels = maxSidePixels;
    resize();
  } ////// end constructor //////


  private void resize() {
    image = Scalr.resize(image, maxSidePixels);
    repaint();
  }

  public void resize(int maxSidePixels) {
    
    image = Scalr.resize(image, maxSidePixels);
    repaint();
  }


  @Override
  public void paintComponent(Graphics g) {
     g.drawImage(image, 0, 0, null);  // args: image, x, y, ImageObserver
  }

    @Override
  public Dimension getMinimumSize()   { return getPreferredSize(); }
  @Override
  public Dimension getPreferredSize() { return new Dimension(image.getWidth(), image.getHeight()); }
  //@Override
  //public Dimension getMaximumSize() { return new Dimension(panelWidthPref + 100, panelHeightPref + 100); }


} //////////////////// end class ImageResizeToPanel /////////////////////////////
